
import UtilsSprite from '../Utils.Sprite/UtilsSprite';

const _init = Symbol('_init');
const _error = Symbol('_error');
export class UtilsLightSourceAndCircumference {
    constructor(_options, _callback, _that) {
        if (!_options) return this[_error]('no options?');
        this.options = _options;
        this.callback = _callback;
        this[_init](_that);
    }

    [_init](_that) {
        _that[this.options.closeKey] = false;
        this.options.lightWeapon.forEach((element, index) => {
            _that[`defTweens${index}`] = _that.add.pointlight(element.x, element.y, element.col, element.ra, element.int, element.att);
            _that.tweens.add({ targets: _that[`defTweens${index}`], radius: element.tweens.ra, yoyo: element.tweens.yoyo, duration: element.tweens.dura, repeat: element.tweens.rep, ease: 'Sine.inOut' });
        });
        _that[this.options.oldWeaponKey].setVisible(false);
        _that[this.options.newWeaponKey[0].key] = _that.add.image(this.options.newWeaponKey[0].add.x, this.options.newWeaponKey[0].add.y, this.options.newWeaponKey[0].add.key);

        new UtilsSprite([{
            key: this.options.sprite.key,
            spriteKey: this.options.sprite.spriteKey,
            play: this.options.sprite.playKey,
            sprXY: {
                x: 0,
                y: 0
            },
            scal: this.options.sprite.scal,
            vis: this.options.sprite.vis
        }], 'static', _that);

        _that.path = { t: 0, vec: new Phaser.Math.Vector2() };
        _that.curve = new Phaser.Curves.Ellipse(this.options.curve.x, this.options.curve.y, this.options.curve.xRa, this.options.curve.yRa)
        .setRotation(this.options.curve.rot);

        _that.tweens.add({
            targets: _that.path,
            t: 1,
            ease: 'Linear',
            duration: this.options.curveTweens.dura,
            repeat: this.options.curveTweens.rep
        });

        _that[this.options.newWeaponKey[1].key] = _that.add.image(this.options.newWeaponKey[1].add.x, this.options.newWeaponKey[1].add.y, this.options.newWeaponKey[1].add.key);

        _that[this.options.updatakey] = true;

        this.callback('done');
    }

    [_error](err) {
        throw err;
    }
};

export class UtilsLightSourceAndCircumferenceForUpdata {
    static init(_key, _that) {
        _that.curve.getPoint(_that.path.t, _that.path.vec);
        _that[_key].x = _that.path.vec.x;
        _that[_key].y = _that.path.vec.y;
    }
}